<?php

defined( 'IN_DICE' ) or die( 'Access Error!' );

class test extends control {
  
  public function __construct() {
    if( PRODUCT_ENV !== false ) { //产品环境不是测试,则直接退出
      include DIR_CTL . 'admin/admincontrol.php';
      $c = new admincontrol();
      func::smarty()->compile_dir = str_ireplace('admin', '', func::smarty()->compile_dir);
      $c->_logcheck();
    }
  }
  
  public function index() { //本地测试游戏
    $uid = func::input( 'uid', 'i', 'COOKIE' );
    all::$aU = model::member()->getpbyuid( $uid, false );
    if( empty( all::$aU ) ) { //没有注册,注册用户
      func::redirect( './index.php?m=test&a=in&debug=1' );
    }
    
    $aOnline = model::online()->get( all::$aU['uid'] );
    if( empty( $aOnline ) ) {
      $aOnline = model::online()->insert( all::$aU['uid'], all::$aU['pfid'] ); //插入到用户在线表并生成olkey
    }
    $aFlash = $this->getSwfVars( all::$aU, $aOnline['olkey'] );
    $aFlash['editurl'] = all::$aOut['baseurl'] . '?m=game&a=edit';
    $aFlash['payurl'] = all::$aOut['baseurl'] . '?m=game&a=pay';
    $aFlash['apiurl'] = all::$aOut['baseurl'] . '?m=test';

    all::$aOut['aFlashvar'] = $aFlash;
    all::$aOut['flashvar'] = http_build_query( $aFlash );

    $aBN = array(
      'url1' => all::$aOut['imgurl'] . 'bnmycard.swf',
      'js1' => all::$aOut['baseurl'] . '?m=game&a=pay',
      'url2' => all::$cfg['swfurl'] . 'bnbc.swf',
      'js2' => all::$aOut['baseurl'] . '?m=game&a=compensation',
    );
    all::$aOut['bnvar'] = http_build_query( $aBN );
    
    func::display( all::$aOut, 'index.htm', '' );
  }
  
  public function out() { //测试退出
    setcookie( 'uid', '', -36000 );
    func::redirect( './index.php?m=test&a=in&debug=1' );
  }
  
  public function in() { //测试登陆
    $uid = func::input( 'uid', 'i', 'COOKIE' );
    if( $uid > 0 ) {
      func::redirect( './index.php?m=test&debug=1' );
    }

    $array = array();
    if ( $unick = func::input( 'unick' ) ) {
      $aU = model::member()->getonebyunick( $unick );
      if( !$aU ) {
        $aTemp = array( //插入用户
          'puid' => mt_rand( 10000, 20000 ),
          'pfid' => 10000,
          'usid' => 0,
          'sex' => mt_rand( 0, 1 ),
          'uname' => $unick,
          'uface' => '',
        );
        $uid = model::member()->insert( $aTemp );
        $aU = model::member()->getpbyuid( $uid );
      }
    }

    if ( $uid = func::input( 'uid', 'i' ) ) {
      $aU = model::member()->getpbyuid( $uid );
    }
    if( isset( $aU['uid'] ) && ( $aU['uid'] > 0 ) ) {
      setcookie( 'uid', $aU['uid'] );
      func::redirect( './index.php?m=test&debug=1' );
    }
    all::$aOut['u100'] = model::member()->get100();
    
    func::display( all::$aOut, 'login.htm', '' );
  }

  public function pay() {
    $uid = func::input( 'uid', 'i', 'COOKIE' );
    all::$aU = model::member()->getpbyuid( $uid, false );
    $param = array(
      'uid' => $uid,
      'puid' => all::$aU['puid'],
      'returl' => all::$aOut['baseurl'] . '?m=test&debug=1',
    );
    all::$aOut['pcenterurl'] = model::pclient( 1 )->geturl($param);
    func::display( all::$aOut, 'pt.htm', '' );
  }
}










